Skip to content

fix(sql): support sqlc.arg in ORDER BY expressions#4429

Open
mujib77 wants to merge 1 commit intosqlc-dev:mainfrom
mujib77:fix-orderby-sqlc-arg
Open

fix(sql): support sqlc.arg in ORDER BY expressions#4429
mujib77 wants to merge 1 commit intosqlc-dev:mainfrom
mujib77:fix-orderby-sqlc-arg

Conversation

@mujib77
Copy link
Copy Markdown

@mujib77 mujib77 commented May 7, 2026

Summary

This fixes handling of sqlc.arg() inside ORDER BY expressions during named parameter rewriting.

While testing queries using named parameters in conditional ordering logic, I noticed that parameters used inside ORDER BY expressions were not being rewritten correctly. The rewrite flow was missing these cases during parameter processing.

This change updates the rewrite handling and adds regression test coverage for the behavior.

Example

Query:

SELECT ID
FROM Sequence
WHERE SeriesID = ?1
ORDER BY (Name = sqlc.arg(name)) DESC, ID
LIMIT 1;

Before this change, the named parameter inside the ORDER BY expression was not rewritten correctly.

After this change, sqlc.arg(name) is properly detected and rewritten during parameter processing.

Changes

  • Updated named parameter rewrite handling for ORDER BY expressions
  • Added regression test coverage in parameters_test.go
  • Verified rewrite package tests with:
go test ./internal/sql/rewrite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant